library(SDMTools)

work.dir = "H:/Barra Work Directory/current.esoclim/"; setwd(work.dir)

pnts=cbind(x=c(112,116,116,112), y=c(-11,-11,-18.5,-18.5))
cols = colorRampPalette(c('skyblue','slateblue','forestgreen','yellow','red'))(101)
months=c('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December')

zlim=NULL
for (ii in 1:12) { cat(ii,'\n')
      tasc = read.asc.gz(paste("tasmax", sprintf('%02i',ii), ".asc.gz",sep=''))
      zlim=range(c(zlim,as.vector(tasc)),na.rm=TRUE)
}
#combine min from tasmin with max from tasmax for zlim
zlim=c(-6,42) #given what you know about zlim

png(paste('tasmax.png',sep=''), width=28, height=19, units='cm', res=300, pointsize=5, bg='white')


#make 4 columns of 3 rows of images 
par(mfrow=c(3,4),mar=c(0,1,0,1), oma=c(0,3,3,0))


#loop
for (ii in 1:12) {  cat(ii,'\n')
      tasc = read.asc.gz(paste("tasmax", sprintf('%02i',ii), ".asc.gz",sep=''))
      image(tasc, zlim=zlim, ann=FALSE,axes=FALSE,col=cols)
      text (130, -40, months[ii], cex=4)
      if (ii==1) {legend.gradient(pnts,cols=cols,limits=round(zlim), title='Maximum Tepmerature', cex=3)}

      }

dev.off()
